
  function getPhonePassord(){
  	  var phone=$("#phone").val();
  	  var code=$("#code").val();
  	  var password=$("#password").val();
  	  var password2=$("#password2").val();
  	  
  	  if (!(/^1(3|4|5|7|8)\d{9}$/.test(phone))){ 
	            	alert("手机号码有误");
	            	return;
	  }
  	  if(password==password2){
  	  	     
		$.ajax({
 url: urlcore + "/api/user/getPhonePassord?phone="+phone+"&code="+code+"&password="+password,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
                      toLogin(phone,password);
                      
				} else {
				  alert("注册失败！");
				  
				}

			},
			error: function() {
				alert("error");
			}
		});

  	  	     
  	  }else{
  	  	   alert("密码不一致!");
	            	return;
  	  }
  }


function Getvalidationcode(){
	
	  var phone=$("#phone").val();
	   if (!(/^1(3|4|5|7|8)\d{9}$/.test(phone))){    
	            	alert("手机号码有误");
	            	return;
	  }else{  
	  	$.ajax({
			url: urlcore +"/api/user/selectuserag?types=1&iphone="+phone,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success:function(data){
				if(data.success == true){
					 selectGoodsList2(phone);
				}else{
					alert("请勿重复注册!");
				}
				
			},
			error:function() {
				/* Act on the event */
				alert("error");
			}
		});
	  }
     
}



function  selectGoodsList2(phone){
		$.ajax({
 url: urlcore + "/api/user/getPhoneCode?types=1&phone="+phone,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
                   alert("注意查收");                    
				} else {
				alert("error1");
				}
			},
			error: function() {
				alert("error");
			}
		});
}



function toLogin(phone,password){
	if(phone!="" && password!=""){
		$.ajax({
			url: urlcore + "/api/login/loginPhoneweixin?phone="+phone+"&password="+password,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success:function(data){
				if (data.success == true) {					
					//设置cookie
					var domain_url = urlcore.split('://')[1];
					if (domain_url.indexOf(':') > -1) {
						domain_url = domain_url.split(':')[0];
					}else{
						domain_url = domain_url.split('/')[0];
					}
					document.cookie = "JSESSIONID="+data.data.token+";path=/;domain="+domain_url;
					window.location.href="index.html";
				} else {
					alert(data.msg);
				}
			},
			error:function() {
				/* Act on the event */
				alert("error");
			}
		});
	} 
}
